package com.easy.goods.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.Category;
import com.easy.goods.mapper.ICategoryMapper;
import com.easy.goods.service.ICategoryService;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;

@Service
public class CategoryService implements ICategoryService {
	@Autowired
	ICategoryMapper categorymapper;

	@Override
	public List<Category> getCategoryByPage(IPage page, Category category) {
		QueryWrapper<Category> qw = new QueryWrapper();
		qw.like("name", category.getName());
		qw.like("code", category.getCode());
		qw.like("description", category.getDescription());
		List<Category> result=categorymapper.selectList(page, qw);
		return result;
	}

	@Override
	public List<Category> getSuperCategory() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Category> getCategoryByID() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public List<Category> getCategoryParentANDChildren() {
		MPJLambdaWrapper<Category> qw = JoinWrappers.lambda(Category.class).selectAll()
				.selectCollection(Category.class, Category::getCategoryList)
				.leftJoin(Category.class, Category::getPId, Category::getId);
		List<Category> result = categorymapper.selectJoinList(Category.class, qw);
		return result;
	}

	@Override
	public List<Category> getCategoryBySuperID(Integer superid) {
		MPJLambdaWrapper<Category> qw = JoinWrappers.lambda(Category.class).eq("pid", superid).selectAll();
		List<Category> result = categorymapper.selectJoinList(Category.class, qw);
		return result;
	}

	@Override
	public Category addCategory(Category category) {
		categorymapper.insert(category);
		return category;
	}

	@Override
	public int delCategoryByID(Integer id) {
		int result=categorymapper.deleteById(id);
		return result;
	}

	@Override
	public Category editCategory(Category category) {
		int result=categorymapper.updateById(category);
		category=categorymapper.selectById(category.getId());
		return category;
	}


}
